

package com.hazelcast.test.backup;

import java.util.concurrent.Callable;

/**
 * Base class for {@link Callable} classes which need a special TCCL to be set.
 *
 * @param <V> the result type of method {@code call}
 */
abstract class AbstractClassLoaderAwareCallable<V> implements Callable<V> {

    private final ClassLoader classLoader = AbstractClassLoaderAwareCallable.class.getClassLoader();

    @Override
    public final V call() throws Exception {
        Thread thread = Thread.currentThread();
        ClassLoader contextClassLoader = thread.getContextClassLoader();
        try {
            thread.setContextClassLoader(classLoader);
            return callInternal();
        } finally {
            thread.setContextClassLoader(contextClassLoader);
        }
    }

    abstract V callInternal() throws Exception;
}
